#include <stdio.h>
#include <unistd.h>
#include <string.h>

// 全局变量定义 - 用于测试DWARF变量类型解析
int global_int_var = 42;
float global_float_var = 3.14f;
double global_double_var = 2.71828;
char global_char_var = 'A';
char global_string_var[] = "Hello, DWARF!";
int global_array_var[5] = {1, 2, 3, 4, 5};

// 结构体定义
struct test_struct {
    int id;
    float value;
    char name[32];
};

struct test_struct global_struct_var = {
    .id = 1001,
    .value = 99.9f,
    .name = "Test Struct"
};

// 联合体定义
union test_union {
    int int_val;
    float float_val;
    char char_val;
};

union test_union global_union_var = { .int_val = 999 };

// 函数声明
void print_variables();

int main() {
    printf("\t变量类型测试程序启动 (PID: %d)\n", getpid());
    printf("\t全局变量地址信息:\n");
    printf("\tglobal_int_var: %p\n", &global_int_var);
    printf("\tglobal_float_var: %p\n", &global_float_var);
    printf("\tglobal_double_var: %p\n", &global_double_var);
    printf("\tglobal_char_var: %p\n", &global_char_var);
    printf("\tglobal_string_var: %p\n", &global_string_var);
    printf("\tglobal_array_var: %p\n", &global_array_var);
    printf("\tglobal_struct_var: %p\n", &global_struct_var);
    printf("\tglobal_union_var: %p\n", &global_union_var);
    
    // 局部变量
    int local_int = 123;
    float local_float = 1.23f;
    double local_double = 4.56;
    char local_char = 'B';
    char local_string[20] = "Local String";
    
    printf("\t局部变量地址信息:\n");
    printf("\tlocal_int: %p\n", &local_int);
    printf("\tlocal_float: %p\n", &local_float);
    printf("\tlocal_double: %p\n", &local_double);
    printf("\tlocal_char: %p\n", &local_char);
    printf("\tlocal_string: %p\n", &local_string);
    
    // 循环执行，便于调试器中断
    for (int i = 0; i < 10; i++) {
        printf("\t迭代 %d - 全局int值: %d\n", i, global_int_var);
        print_variables();
        sleep(2);
    }
    
    printf("\t测试程序结束\n");
    return 0;
}

void print_variables() {
    printf("\t变量值: int=%d, float=%.2f, double=%.5f, char=%c\n",
           global_int_var, global_float_var, global_double_var, global_char_var);
    printf("\t字符串: %s\n", global_string_var);
    printf("\t数组: [%d, %d, %d, %d, %d]\n",
           global_array_var[0], global_array_var[1], global_array_var[2],
           global_array_var[3], global_array_var[4]);
    printf("\t结构体: id=%d, value=%.1f, name=%s\n",
           global_struct_var.id, global_struct_var.value, global_struct_var.name);
    printf("\t联合体: int_val=%d\n", global_union_var.int_val);
}